package ru.jexp.rcp.supply.swtext;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

import ru.jexp.rcp.supply.img.JExpImageLink;
import ru.jexp.rcp.supply.mui.JExpSupplyMessages;

public abstract class JExpDialog extends Dialog
{

	public JExpDialog(Shell parentShell)
	{
		super(parentShell);
	}

	public JExpDialog(IShellProvider parentShell)
	{
		super(parentShell);
	}

	protected abstract String createTitle();

	protected abstract void createControls(Composite parent);

	protected abstract void updateControlsData();

	protected abstract void updateControlsEnable();

	@Override
	protected void configureShell(Shell newShell)
	{
		super.configureShell(newShell);
		newShell.setText(createTitle());
		newShell.setImage(getImageDescription());
	}

	protected Image getImageDescription()
	{
		return JExpImageLink.getImage(JExpImageLink.LOOKUP);
	}

	protected final Control createDialogArea(Composite parent)
	{
		Composite composite = new Composite(parent, SWT.NONE);
		createControls(composite);
		updateControlsData();
		updateControlsEnable();
		return composite;
	}

	@Override
	protected boolean isResizable()
	{
		return true;
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent)
	{
		createButton(parent, IDialogConstants.OK_ID, JExpSupplyMessages.Global_button_add, true);
		createButton(parent, IDialogConstants.CANCEL_ID, JExpSupplyMessages.Global_button_cancel, false);
	}

}